package core;

import world.maps.CurrentMap;
import world.objects.MyChar;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * Created by IntelliJ IDEA.
 * User: Jake
 * Date: 19/12/11
 * Time: 17:47
 * To change this template use File | Settings | File Templates.
 */
public class GameDisplay extends Canvas {
    static BufferedImage toDraw = null;

    public GameDisplay() {
        this.setSize(512, 512);
        this.addKeyListener(new KeyController());
    }

    @Override
    public void paint(Graphics g) {
        if (toDraw != null)
            g.drawImage(toDraw, 0, 0, null);
    }


    public void setGraphics(BufferedImage toDraw) {
        this.toDraw = toDraw;
        repaint();
    }


    public void updateGraphics() {
        BufferedImage temp = new BufferedImage(512, 512, BufferedImage.TYPE_INT_RGB);
        Graphics g2s = temp.getGraphics();
        Image myloc = CurrentMap.c.getImage();
        BufferedImage bi = (BufferedImage) myloc;
        g2s.drawImage(bi.getSubimage(MyChar.getX() - 256, MyChar.getY() - 256, 512, 512), 0, 0, null);
        //g2s.drawImage(bi,0,0,null);
        toDraw = temp;
        repaint();

    }
}
